package com.tantinevincent.process;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.tantinevincent.normalization.INormalizar;
import com.tantinevincent.normalization.MinMaxNormalizar;
import com.tantinevincent.option.Option;
import com.tantinevincent.vector.IVector;
import com.tantinevincent.vector.LabeledVector;

public class OptionExecuteProcess {
	
	private Option option;
	
	public OptionExecuteProcess(Option option){
		this.option = option;
	}
	public List<LabeledVector> execute(List<LabeledVector> vectors){
		if( option.hasNormalization() ){
			vectors = normalize(vectors);
		}
		if( option.hasShuffle() ){
			vectors = shuffle(vectors);
		}
		return vectors;
	}
	private List<LabeledVector> normalize(List<LabeledVector> vectors){
		// load min value and max value to min-max normalizar
		int length = vectors.get(0).length();
		INormalizar normalizar = new MinMaxNormalizar(length);
		for( IVector vector : vectors ){
			normalizar.load(vector);
		}
		// normalize every vector
		List<LabeledVector> normalizedVectors = new ArrayList<LabeledVector>();
		for( LabeledVector vector : vectors ){
			IVector normalizedVector = normalizar.normalize( vector.getBaseVector() );
			LabeledVector lv = new LabeledVector( normalizedVector,vector.getLabel() );
			normalizedVectors.add(lv);
		}
		return normalizedVectors;
	}
	private List<LabeledVector> shuffle(List<LabeledVector> vectors){
		Collections.shuffle(vectors);
		return vectors;
	}
	
}
